#!/usr/bin/env python

import wx

class Groups(object):
    '''Groups class
    
    @author Julot <andy.julot@gmail.com>
    @since Wednesday, February 29, 2012. 09:43 AM'''
    
    def __init__(self, view, presenter):
        self.view = view
        self.presenter = presenter
        self.bind()
    
    def bind(self):
        view  = self.view
        view.Bind(wx.EVT_TEXT_ENTER, self.filter, view.groups.group)
        view.Bind(wx.EVT_COMBOBOX, self.filter, view.groups.group)
        view.Bind(wx.EVT_LIST_ITEM_SELECTED, self.createMessageFromContact,
                  view.groups.members)
        view.Bind(wx.EVT_LIST_ITEM_SELECTED, self.createMessageFromContact,
                  view.groups.contacts)
    
    def filter(self, event):
        self.presenter.groups.filter(event.String)
        self.presenter.message.create(groups=[event.String])
    
    def createMessageFromContact(self, event):
        self.presenter.message.create(contactId=event.Data)
        